package com;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;


@SpringBootApplication
@ServletComponentScan
@EnableConfigurationProperties
public class Application implements EmbeddedServletContainerCustomizer{

//	@Override
//    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//        return application.sources(Application.class);
//    }

//    public static void main(String[] args) {
//        SpringApplication.run(Application.class, args);
//    }



    public static void main(String... args) throws UnknownHostException {
        SpringApplication app = new SpringApplication(Application.class);
        Environment env = app.run(args).getEnvironment();
        System.out.print("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://127.0.0.1:{}\n\t" +
                        "External: \thttp://{}:{}\n----------------------------------------------------------"+
                env.getProperty("spring.application.name")+"\n"+
                InetAddress.getLocalHost().getHostAddress()+
                ":"+env.getProperty("server.port")+"\n");
    }


    @Override
    public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
        configurableEmbeddedServletContainer.setPort(8011);
    }

    //    @Bean
//    public void customizer(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer){
//        return args -> {
//            configurableEmbeddedServletContainer.setPort(8014);
//        };
//    }
}